﻿using System;
using ALDIOrganizer.Properties;

namespace ALDIOrganizer
{
    public class WorkingHoursForBinding
    {
        /* At the risk of making my code below look like one of the snippets on TheDailyWTF.com
         * - it's the simpliest way really. In .NET, you cannot bind an array
         * to a DataGridView if you want its elements to be displayed IN ONE ROW
         * (first element, second element, third element etc. HORIZONTALLY).
         * Each element will be given its own row.
         * Databinding simply
         * 
         * Thankfully week only has got 7 days. If the array could be longer - eg. 100
         * or 1 000 000 elements - I would use Reflection Emit (TypeBuilder) to dynamically
         * generate a MyCellType with a given number of string fields (equal to the length of the
         * array).
         * It's lot of work though and not worth it in this case. */
        public string add
        {
            get
            {
                return Program.Logged.CanEditTemplates ?
                    Resources.DATAGRID_WorkingHours_AddAnotherRow :
                    String.Empty;
            }
        }

        #region d1-d7 accessors
        public string d1
        {
            get
            {
                return Hours[0].GetToString;
            }
        }
        public string d2
        {
            get
            {
                return Hours[1].GetToString;
            }
        }
        public string d3
        {
            get
            {
                return Hours[2].GetToString;
            }
        }
        public string d4
        {
            get
            {
                return Hours[3].GetToString;
            }
        }
        public string d5
        {
            get
            {
                return Hours[4].GetToString;
            }
        }
        public string d6
        {
            get
            {
                return Hours[5].GetToString;
            }
        }
        public string d7
        {
            get
            {
                return Hours[6].GetToString;
            }
        }
        #endregion

        public WorkingHoursSpan[] Hours;

        public WorkingHoursForBinding(WorkingHoursSpan[] pWorkingHours)
        {
            if (pWorkingHours.Length != 7)
            {
                throw new ArgumentException();
            }
            Hours = pWorkingHours;
        }

        public WorkingHoursForBinding[] GetDataSource()
        {
            return new[] { this };
        }
    }


    

    

}
